package com.agy.filemanager.service.impl;

import com.agy.filemanager.entity.DcBaseRole;
import com.agy.filemanager.entity.DcManagerInfo;
import com.agy.filemanager.entity.TreeModel;
import com.agy.filemanager.mapper.DcSystemBaseRoleDao;
import com.agy.filemanager.mapper.DcSystemDao;
import com.agy.filemanager.service.DcSystemBaseRoleService;
import com.agy.filemanager.service.DcSystemService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 系统设置-角色维护
 * @author jpf
 */
@Service
public class DcSystemBaseRoleServiceImpl implements DcSystemBaseRoleService {
    @Autowired
    private DcSystemBaseRoleDao dcSystemBaseRoleDao;

    /**
     * 根据关键字分页查询角色表数据，关键字初始默认为空
     * -select
     * @return
     */
    @Override
    public Page selectBaseRole(int pageNum, int pageSize, String account) {
        Page page = PageHelper.startPage(pageNum,pageSize);
        List<DcBaseRole> list = this.dcSystemBaseRoleDao.selectBaseRole(account);
        return page;
    }

    /**
     * 角色禁用与启用
     * @param id
     * @param isyes
     * @return
     */
    public int banById (String id, Boolean isyes){
        int value = 1;
        if(isyes){
            value =0;
        }
        return dcSystemBaseRoleDao.banById(id,value);
    };

    /**
     *角色新增
     * @param entity
     */
    public void addBaseRole(DcBaseRole entity){

        String id = UUID.randomUUID().toString().replaceAll("-", "");
        entity.setId(id);
        try {
            List<DcBaseRole> list = dcSystemBaseRoleDao.getMaxSort();
            DcBaseRole dcBaseRole= list.get(0);
            entity.setSort(dcBaseRole.getSort()+1);
            dcSystemBaseRoleDao.addBaseRole(entity);
        }catch (Exception ex){
            ex.printStackTrace();
        }
    }

}
